﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Downplay.Alchemy.Dynamic;

namespace Downplay.Alchemy.Tests.Dynamics {
    [TestFixture]
    public class DictionaryTests {

        [Test]
        public void BehavesLikeDictionary() {
            dynamic stuff = new Stuff();

            stuff["Foo"] = "Bar";
            stuff["Two"] = "One";

            Assert.That(stuff.ContainsKey("Bar"), Is.EqualTo(false));
            Assert.That(stuff.ContainsKey("Foo"), Is.EqualTo(true));
            Assert.That((string)stuff["Foo"], Is.EqualTo("Bar"));
            stuff.Remove("Foo");
            Assert.That(stuff.ContainsKey("Foo"), Is.EqualTo(false));
            Assert.That(stuff.ContainsKey("Two"), Is.EqualTo(false));
            Assert.That(stuff.Foo == null, Is.EqualTo(true));
        }

        [Test]
        public void PeriodsMapToDictionaryOrProperties() {
            dynamic stuff = new Stuff();
            stuff["Foo.Bar"] = "Car";

            Assert.That(stuff.ContainsKey("Foo"), Is.EqualTo(true));
            Assert.That(stuff.ContainsKey("Foo.Bar"), Is.EqualTo(true));
            Assert.That(stuff.Foo.ContainsKey("Bar"), Is.EqualTo(true));
            Assert.That(stuff.Foo.Supertype(), Is.EqualTo("Object"));
            Assert.That(stuff.Foo.Bar, Is.EqualTo("Car"));
            Assert.That((string)stuff.Foo["Bar"], Is.EqualTo("Car"));
            Assert.That((string)stuff["Foo.Bar"], Is.EqualTo("Car"));
        }

    }
}
